package com.smart.home.interceptor;

import com.smart.home.context.UserContext;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;


//TODO 这个类是清理线程上下文
@Component
public class HomeContextClearingFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        Filter.super.init(filterConfig);
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        try {
            chain.doFilter(request, response);
        } finally {
            UserContext.clear();// 请求结束后清理上下文

        }
    }

    @Override
    public void destroy() {
        Filter.super.destroy();
    }


}
